package dao

import (
	"go-demo/model"
	"time"
)

// 添加新的点赞
func CreateLike(userid int64, videoid int64) {
	like := model.Like{UserId: userid, VideoId: videoid, CreateTime: time.Now()}
	Db.Create(&like)
}

// 删除点赞
func DeleteLike(userid int64, videoid int64) error {
	var like model.Like
	err := Db.Model(&model.Like{}).Where("user_id = ? && video_id = ?", userid, videoid).Delete(&like).Error

	return err
}

// 通过用户id在点赞表中查询视频列表
func GetVideoByUserIDLike(id int64) ([]model.Video, error) {
	var videoId []model.Like
	var videos []model.Video

	result := Db.Where("user_id = ?", id).Find(&videoId)
	if result.Error != nil {
		return nil, result.Error
	}
	for k := range videoId {
		video, _ := GetVideoByID(videoId[k].VideoId)
		videos = append(videos, video)
	}
	return videos, nil
}
